package com.stylefeng.guns.common.util;

import java.math.BigDecimal;

/**
 * BigDecimal工具类
 */
public class BigDecimalUtil {

    private static final int TWO_DECIMAL = 2;

    private BigDecimalUtil() {
    }

    /**
     *
     */
    public static BigDecimal RoundUpDecimal(BigDecimal value, int scale) {
        return value.setScale(scale, BigDecimal.ROUND_UP);
    }

    public static BigDecimal RoundUpTwoDecimal(BigDecimal value) {
        if (value == null)
            return null;
        return RoundUpDecimal(value, TWO_DECIMAL);
    }

    public static BigDecimal RoundCeilingDecimal(BigDecimal value, int scale) {
        if (value == null)
            return BigDecimal.ZERO;
        return value.setScale(scale, BigDecimal.ROUND_CEILING);
    }

    public static BigDecimal RoundCeilingTwoDecimal(BigDecimal value) {
        return RoundCeilingDecimal(value, TWO_DECIMAL);
    }

    public static BigDecimal RoundDownDecimal(BigDecimal value, int scale) {
        return value.setScale(scale, BigDecimal.ROUND_DOWN);
    }

    public static BigDecimal RoundDownTwoDecimal(BigDecimal value) {
        if (value == null)
            return BigDecimal.ZERO;
        return RoundDownDecimal(value, TWO_DECIMAL);
    }

}
